﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
namespace DAL
{
   
   public  class GoodsDAL
    {
        DBHelper db = new DBHelper();
        public int GoodsAdd(string goodsname,string goodstype,int goodsnum,int goodsprice,string goodsjtime,string  goodzhuant)    //添加
        {
            string sql = string.Format("INSERT INTO [dbo].[Goods]([goodsname],[goodstype],[goodsnum],[goodsprice],[goodsjtime],[goodszhuangt],[goodsstatus])VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", goodsname, goodstype, goodsnum, goodsprice, goodsjtime, goodzhuant,1);
            return db.zsg(sql) ;
        }
        public DataTable show()  //显示dgv
        {
            string sql = string.Format("select * from Goods where goodsstatus ='1'");
            return db.cx(sql);
        }

        public DataTable cxgoods(string goodsname, int allgoods,int goodsxiajia)//查询
        {
            string sql = string.Format("select * from Goods where 1>0 and goodsstatus ='1' ");
            if (!string.IsNullOrEmpty(goodsname))
            {
                sql += string.Format("and goodsname like '%{0}%' ",goodsname);
            }
            if (allgoods>0)
            {
                sql += string.Format("or goodsstatus ='0'");
            }
            if (goodsxiajia == 2)
            {
                sql += string.Format("and goodszhuangt='下架'");
            }
            return db.cx(sql) ;
        }
        public int goodsModify(string goodsname, string goodstype, int goodsnum, int goodsprice, string goodsjtime, string goodszhuant,int id ) //修改
        {
            string sql = string.Format("UPDATE [dbo].[Goods]SET [goodsname] = '{0}',[goodstype] = '{1}',[goodsnum] =  '{2}',[goodsprice]= '{3}',[goodsjtime] = '{4}',[goodszhuangt] =  '{5}'WHERE id='{6}'", goodsname, goodstype, goodsnum, goodsprice, goodsjtime, goodszhuant, id);
            return db.zsg(sql);
        }
        public DataTable Modifyshow(int id)//修改查询
        {
            string sql = string.Format("select * from Goods where id='{0}'",id);
            return db.cx(sql);
        }
        public int mModifyDel(int id)    // 删除用户
        {
            String sql = string.Format("update Goods set goodsstatus ='{0}' where id='{1}' ", 0, id);
            return db.zsg(sql);
        }
    }
}
